# 1. excel 多表合并
import  pandas as pd
import  glob    # 操作文件的相关模块
filelocation  = glob.glob(r'data/*.xlsx')
filearray = []
# 遍历指定目录
for filename in filelocation:
    filearray.append(filename)
res = pd.read_excel(filearray[0])   # 读第一个
# 顺序读取excel文件并合并
for i in range(1,len(filearray)):
    A = pd.read_excel(filearray[i])
    res = pd.concat([res,A],ignore_index=True,sort=False)
print(res.index)
# 写入excel文件并保存
writer = pd.ExcelWriter('./all.xlsx')
# res.to_excel(writer , 'Sheet1')
res.to_excel(writer )   # pandas 3.0后 只需要 writer参数
writer._save()

